using System.Linq;
using AutoMapper;
using Pay.DTO;
using Pay.Data;
using Pay.IService;

namespace Pay.Service.AutoMapper {
	public class RoleMapper : IStartupDto {
		private IMapperConfigurationExpression _cfg;
		public RoleMapper(IMapperConfigurationExpression cfg) {
			_cfg = cfg;
		}
		public void Execute() {
			Create();
		}
		protected virtual void Create() {
			_cfg.CreateMap<role_dto, Role>()
				.ForMember(dest => dest.Id, src => src.MapFrom(c => c.id))
				.ForMember(dest => dest.Name, src => src.MapFrom(c => c.name))
				.ForMember(dest => dest.Remark, src => src.MapFrom(c => c.remark));
			_cfg.CreateMap<Role, role_dto>()
				.ForMember(dest => dest.id, src => src.MapFrom(c => c.Id))
				.ForMember(dest => dest.name, src => src.MapFrom(c => c.Name))
				.ForMember(dest => dest.remark, src => src.MapFrom(c => c.Remark))
				.ForMember(dest => dest.feature_ids, src => src.MapFrom(c => c.RoleFeatures.Select(o => o.FeatureId)));
		}
	}
}
